//路由懒加载
const Home = ()=>import('@/pages/Home')
const Login = ()=>import('@/pages/Login')
const Register= ()=>import('@/pages/Register')
const Search= ()=>import('@/pages/Search')
const Detail = ()=>import('@/pages/Detail')
const AddCartSuccess= ()=>import('@/pages/AddCartSuccess')
const ShopCart= ()=>import('@/pages/ShopCart')
const Trade = ()=>import('@/pages/Trade')
const  Pay= ()=>import('@/pages/Pay')
const PaySuccess= ()=>import('@/pages/PaySuccess')
const Center= ()=>import('@/pages/Center')
const MyOrder= ()=>import('@/pages/Center/MyOrder')
const GroupOrder= ()=>import('@/pages/Center/GroupOrder')


export default [
    {
        path:'/home',
        component:Home,
    },
    {
        path:'/login',
        component:Login,
        meta:{
            isHidden:true
        }
    },
    {
        path:'/register',
        component:Register,
        meta:{
            isHidden:true
        }
    },
    {
        path:'/search/:keyword?',
        name:'search',
        component:Search,
        props(route){
            return{
                keyword:route.params.keyword,
                queryMsg:route.query.querymsg,
            }
        }
    },
    {
        path:'/detail/:skuId',
        component:Detail,
        
    },
    {
        path:'/addcartsuccess',
        component:AddCartSuccess,
        beforeEnter: (to, from, next) => {
            let skuNum =to.query.skuNum
            let skuInfo=JSON.parse(sessionStorage.getItem('skuInfo'))
            if(skuNum&&skuInfo){
                next()
            }else{
                next(false)
            }
        }
    },
    {
        path:'/shopcart',
        component:ShopCart,
        
    },
    {
        path:'/trade',
        component:Trade,
        beforeEnter: (to, from, next) => {
            if(from.path==='/shopcart'){
                next()
            }else{
                alert('只有从购物车页面才能跳转到交易页面')
                next(false)
            }
        }
    },
    {
        path:'/pay',
        name:'pay',
        component:Pay,
        beforeEnter: (to, from, next) => {
            if(from.path==='/trade'){
                next()
            }else{
                alert('只有从交易页面才能跳转到支付页面')

                next(false)
            }
        }
    },
    {
        path:'/paysuccess',
        component:PaySuccess,
        beforeEnter: (to, from, next) => {
            if(from.path==='/pay'){
                next()
            }else{
                alert('只有从支付页面才能跳转到支付成功页面')

                next(false)
            }
        }
    },
    {
        path:'/center',
        component:Center,
        children:[
            {
                path:'myorder',
                component:MyOrder
            },
            {
                path:'grouporder',
                component:GroupOrder
            }
        ]
    },
    {
        path:'/',
        redirect:'/home'
    },
]